package ToYesterday.Day12_CircleQueue;

public class CircleQueue {
}
class MyCircularQueue {

    class Que{
        int [] queue;
        int length;
        int front;
        int rear;
        int count;

        public Que(int k) {
            this.queue = new int[k];
            this.length = k;
            front=0;
            rear=0;
            count=0;
        }
    }
    private Que que;
    public MyCircularQueue(int k) {
        que = new Que(k);
    }

    public boolean enQueue(int value) {
        if (que.count==que.length)return false;
        que.queue[que.rear]=value;
        que.rear = (que.rear+1)%que.length;
        que.count++;
        return true;
    }

    public boolean deQueue() {
        if (que.count==0)return false;
        que.front = (que.front+1)%que.length;
        que.count--;
        return true;
    }

    public int Front() {
        if (que.count==0)return -1;
        return que.queue[que.front];
    }

    public int Rear() {
        if (que.count==0)return -1;

        if (que.rear==0)return que.queue[que.length-1];
        return que.queue[que.rear-1];
    }

    public boolean isEmpty() {
        if (que.count>0)return false;
        return true;

    }

    public boolean isFull() {
        if (que.count==que.length)return true;
        return false;
    }
}

/**
 * Your MyCircularQueue object will be instantiated and called as such:
 * MyCircularQueue obj = new MyCircularQueue(k);
 * boolean param_1 = obj.enQueue(value);
 * boolean param_2 = obj.deQueue();
 * int param_3 = obj.Front();
 * int param_4 = obj.Rear();
 * boolean param_5 = obj.isEmpty();
 * boolean param_6 = obj.isFull();
 */